package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.inspection.InspectionTaskDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.inspection.InspectionTaskVO;
import com.bf.electroplating.pojo.vo.sysuser.UserListVO;
import com.bf.electroplating.service.InspectionTaskService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inspection-task")
@Tag(name = "巡检任务", description = "巡检任务管理")
public class InspectionTaskController {

    @Resource
    private InspectionTaskService inspectionTaskService;

    // 获取巡检人员
    @GetMapping("/getInspectors")
    @Operation(summary = "获取巡检人员列表", description = "获取巡检人员列表")
    public ResultVO<List<UserListVO>> getInspectors() {
        return ResultVO.ok(inspectionTaskService.getInspectors());
    }

    @PostMapping("/list")
    @Operation(summary = "获取巡检任务列表", description = "分页获取巡检任务列表信息")
    public ResultVO<Page<InspectionTaskVO>> getTaskList(@RequestBody InspectionTaskDTO dto) {
        return ResultVO.ok(inspectionTaskService.getTaskList(dto));
    }

    @PostMapping("/getTaskById")
    @Operation(summary = "获取巡检任务详情", description = "根据ID获取巡检任务详细信息")
    public ResultVO<InspectionTaskVO> getTaskById(@RequestBody IdDTO id) {
        return ResultVO.ok(inspectionTaskService.getTaskById(id.getId()));
    }

    @Idempotent
    @PostMapping("/saveTask")
    @Operation(summary = "新增巡检任务", description = "新增巡检任务信息")
    public ResultVO<Boolean> saveTask(@RequestBody InspectionTaskVO vo) {
        return ResultVO.ok(inspectionTaskService.saveTask(vo), "保存成功");
    }
    @Idempotent
    @PostMapping("/updateTask")
    @Operation(summary = "修改巡检任务", description = "修改巡检任务信息")
    public ResultVO<Boolean> updateTask(@RequestBody InspectionTaskVO vo) {
        return ResultVO.ok(inspectionTaskService.updateTask(vo), "保存成功");
    }

    @PostMapping("/deleteTask")
    @Operation(summary = "删除巡检任务", description = "根据ID删除巡检任务信息")
    public ResultVO<Boolean> deleteTask(@RequestBody IdDTO id) {
        return ResultVO.ok(inspectionTaskService.deleteTask(id.getId()), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除巡检任务", description = "批量删除巡检任务信息")
    public ResultVO<Boolean> batchDeleteTask(@RequestBody List<String> ids) {
        return ResultVO.ok(inspectionTaskService.batchDeleteTask(ids), "删除成功");
    }
} 